/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jeppe
 */
public class IniFileReaderWriter {
    private String host;
    private int portnr;
    private String database;
    private String udb;
    private String pdb;
    
    public IniFileReaderWriter(String host, int portnr, String database, String udb, String pdb){
        this.host = host;
        this.portnr = portnr;
        this.database = database;
        this.udb = udb;
        this.pdb = pdb;
    }
    
    
    public void writeFile() throws IOException{
            FileWriter fw = new FileWriter("ini.txt");
            PrintWriter pw = new PrintWriter(fw);
            
            pw.println(host);
            pw.println(database);
            pw.println(portnr);
            pw.println(udb);
            pw.println(pdb);
            
            pw.close();        
    }
    
    public void readFilE() throws FileNotFoundException, IOException{
          FileReader fr = new FileReader("ini.txt");
            BufferedReader br = new BufferedReader(fr);
            
            String [] strArray = new String[5];
            
            for (int i = 0; i < 5; i++) {
                strArray[i] = br.readLine();
//                System.out.println(strArray[i]);
            }
            br.close();
            
            host =                    strArray[0];
            database =                strArray[1];
            portnr = Integer.parseInt(strArray[2]);
            udb =                     strArray[3];
            pdb =                     strArray[4];
    }
    
    // <editor-fold defaultstate="collapsed" desc="Get og set-metoder"> 
    public String getHost() {
        return host;
    }
    
    public int getPortnr() {
        return portnr;
    }

    public String getDatabase() {
        return database;
    }

    public String getUdb() {
        return udb;
    }

    public String getPdb() {
        return pdb;
    }

    public void setHost(String host) {
        this.host = host;
    }
    
    public void setPortnr(int portnr) {
        this.portnr = portnr;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public void setUdb(String udb) {
        this.udb = udb;
    }

    public void setPdb(String pdb) {
        this.pdb = pdb;
    }
    // </editor-fold>
    
}
